<script setup lang="ts">
  import { TOKEN_KEY } from '@/enums/cacheEnum';
  import { getCache, storage } from '@/utils/catch';
  import { onMounted, ref } from 'vue';
  const token = ref(null);
  let ss = ref(null);
  const uToast = ref(null);
  const uCode = ref(null);
  let showToken = ref(false);
  const seconds = 10;
  let tips = '获取token';

  onMounted(() => {
    console.log(uni.$u);
  });

  const getCode = () => {
    uni.showLoading({
      title: '正在获取token',
    });
    setTimeout(() => {
      uni.hideLoading();
      // 这里此提示会被this.start()方法中的提示覆盖
      // 通知验证码组件内部开始倒计时
      token.value = getCache(TOKEN_KEY);
      showToken.value = true;
    }, 1000);
  };
  const codeChange = (text: string) => {
    tips = text;
  };
  const end = () => {
    uni?.$u.toast('倒计时结束');
  };
  const start = () => {
    uni?.$u.toast('倒计时开始');
  };
  const cpText = () => {
    // #ifdef MP-WEIXIN
    uni.setClipboardData({
      data: token.value,
    });
    // #endif
  };
</script>
<template>
  <div class="container">
    <view class="wrap">
      <!-- <u-toast ref="uToast"></u-toast>
      <u-code
        :seconds="seconds"
        @end="end"
        @start="start"
        ref="uCode"
        @change="codeChange"
      ></u-code> -->
      <u-button @tap="getCode" type="primary">{{ tips }}</u-button>
    </view>
    <view class="text" ref="text" v-if="showToken">
      <view>{{ token }}</view>
      <u-button type="primary" :plain="true" :hairline="true" text="细边" @click="cpText"
        >复制</u-button
      >
    </view>
  </div>
</template>
<style lang="scss" scoped>
  .container {
    background: #fff;
    font-size: 24rpx;
    padding: 12px;
  }
  .text {
    word-break: break-all;
  }
</style>
